package demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.aop.Clear;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import demo.model.User;

import java.util.Date;

@Path("/reg")
@Clear
public class RegController extends Controller {
    public void index() {
        render("reg.html");
    }

    public void doReg() {
        String username = getPara("username");
        String password = getPara("password");
        User user = new User();
        user.setUserName(username);
        user.setPassWord(password);
        user.setCreatTime(new Date());
        user.setRealName(username);
        user.setGender("0");
        Boolean flag = user.save();
        renderJson(flag);
        if (flag) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", 0);
            jsonObject.put("msg", "注册成功");
            renderJson(jsonObject);
        } else {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", -1);
            jsonObject.put("msg", "注册失败");
            renderJson(jsonObject);
        }
    }
}
